<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>title</title>
<link rel="stylesheet" href="../assets/agile/css/agile.layout.css">
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconform.css">
<link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/jquery.form.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
</head>
<body>

<div class="scroller create_goods" style="margin-top:0px;">	
<div class="applyfor">
		<form action="" onsubmit="return false" method="post" id="applyagent">
		<img src="../image/agnet_head_bg.jpg" width="100%"/>
		<div class="block10"></div>
		<div class="apply_main">
			<p>在线抢购地方运营代理商权</p>
			<div class="block10"></div>
			<ul>
				<li>
					<span>申请地区：</span>
					<select name="province" id="province"></select>
					<select name="city" id="city"></select>
					<select name="area" id="area"></select>
				</li>
				<li>
					<span>真实姓名：</span>
					<input type="text" name="truename" id="truename" placeholder="请输入真实姓名"/>
				</li>
				<li>
					<span>手机号码：</span>
					<input type="text" name="mobile" id="mobile" placeholder="请输入手机号码"/>
				</li>

				<li>
					<span>输入动态码：</span>
					<input type="text" name="active_code" placeholder="短信查收"  id="active" />
					<span class="get_active">点击获取</span>
				</li>
				</ul>
				<div class="agree">
					<a href="javascript:;" class="agree_a" data-role="checkbox">
			    		<input type="checkbox" value="1" name="agree" id="baskball">
			  			<label for="baskball" class="black">同意协议</label>
			  		</a>
					<a href="javascript:;" class="read_info">阅读协议</a>
				</div>
			<div class="clear"></div>
			<div class="block10"></div>
			<div class="pay_type" style="width:100%;">
				<span style="width:30%;text-align:right;">余额支付：</span>
				申请费用<font color="#3b0" class="amoney">0.00</font>元，当前余额 <font color="#3b0" class="money">0.00</font>
				<a href="javascript:userrecharge();" style="display:none;" class="appfor_c">充值</a>
			</div>
			<div style="width:100%;margin:0 auto;"><button class="btn btn-positive common-btn confirm_apply" type="submit">确认申请</button></div>
			<div class="block10"></div>
			<p>电话抢购地方运营代理商 抢购热线<span class="tel"></span> </p>
			<div class="block20"></div>
		</div>
		</form>
</div>
	    
</div>

<script type="text/javascript" src="../script/area.js"></script>
<script type="text/javascript">
	new PCAS("province","city","area","北京市","市辖区","海淀区");
	function userrecharge(){
		api.openWin({name:'userrecharge',url:'./userrecharge.html',reload:true});
	}
	
	$('.read_info').click(function(){
		api.openWin({
			name:'terms',
			url:'./terms.html',
			reload:true
		});
	});
function funcGoto(){
	window.location.reload();
}
apiready = function(){
	$(function(){
		var tel = {number:''};
		if(!getUserinfo()){
			GetJPData(config.url+'/app.php?act=getsite&key=cell',{},function(data){
				if(data['status']){
					$('.tel').text(data['data']);
					tel.number = data['data'];
				}
			});
			//$.PageDialog.fail('请登录用户');
			localData.set('reload','applyfor');
			randomSwitchBtn('login',api);
		}else{
		var userinfo = getUserinfo();
		GetJPData(config.url+'/app.php?act=applyfor&uid='+userinfo.uid,{},function(data){
			if(data['status'] == 1){
				var userinfo = getUserinfo();
				$('.tel').text(data['tel']);
				tel.number = data['tel'];
				$('.money').text(data['money']);
				$('.amoney').text(data['agent_price']);
				if(data['money'] < data['agent_price']){
					$('.appfor_c').show();
				}
				var province = $('select[name=province]');
				var city = $('select[name=city]');
				var area = $('select[name=area]');
				var active_code = $('input[name=active]');
				var turename = $('input[name=truename]');
				var flag = false;
				$('.get_active').click(function(){
					$('#style').remove();
					var mobile = $('#mobile').val();
					if(mobile == ''){
						$.PageDialog.fail("请输入手机号码");
						return;
					}
					if(flag == true){
						return;
					}
					flag = true;
					var time = 60;
					$(this).html('60 秒');
					var _this = $(this);
					$(this).css('background','#ccc');
					setId = setInterval(function(){
						time--;
						if(time <= 0){
							_this.css('background','#c40c00');
							_this.html('重新获取');
							flag = false;
							clearInterval(setId);
							return;
						}
						_this.html(time+' 秒');
					},1000);
					$.ajax({
						type : 'POST',
						url : config.url+'/app.php?act=aplysendcode&uid='+userinfo.uid,
						data : {'mobile' : mobile},
						success : function(data){
							if(data['status'] == 1){
								$.PageDialog.ok('<s></s>'+data['msg']);
							}else if(data['status'] == 9){
								clearInterval(setId);
								_this.html('点击获取');
								_this.css('background','#c40c00');
								flag = true;
								$.PageDialog.fail(data['msg']);
							}else{
								clearInterval(setId);
								_this.html('点击获取');
								_this.css('background','#c40c00');
								flag = true;
								$.PageDialog.fail(data['msg']);
							}
						}
					});
				});

				//===================
					
		$('#applyagent').submit(function(){
			if ($('#province').val() == '' ) {
				$.PageDialog.fail("请选择省份");
				return false;
			}
			if ($('#city').val() == '' ) {
				$.PageDialog.fail("请选择所在城市");
				return false;
			}
			if ($('#area').val() == '') {
				$.PageDialog.fail("请选择所在区");
				return false;
			}
			if ($('#truename').val() == ''){
				$.PageDialog.fail("请输入真实姓名");
				return false;
				}
			if (!$('#baskball').is(':checked')){
				$.PageDialog.fail("请阅读并同意申请协议");
				return false;
			}
			$(this).ajaxSubmit({
				type : 'POST',
				url : config.url+"/app.php?act=postapplyfor&uid="+userinfo.uid,
				data:{submit:'true'},
				beforeSend : function(){api.showProgress({title:'正在提交','text':''});},
				success : function(data){
					api.hideProgress();
					if(data['status'] == 1){
						api.toast({
						    msg: data['msg'],
						    duration: 3000,
						    location: 'middle'
						});
						setTimeout(function(){
							api.showProgress({title:'正在支付',text:''});
							var userinfo = getUserinfo();
							GetJPData(config.url+'/app.php?act=applypay&uid='+userinfo.uid,{},function(data){
								api.hideProgress();
								if(data['status'] == 1){
									api.alert({msg:data['msg']},function(index,err){
										appClose('applyfor',api);
									});
								}else{
									api.alert({msg:data['msg']});
								}
							});
						},1500);
					}else{
						$.PageDialog.fail(data['msg']);
					}
				},
			});
			return false;
		});
			
		//===========
				
			}else{
				
				if(data['msg']=='您已经是代理商'){
					api.openWin({name:'fansmanage','url':'./fansmanage.html',reload:true});
					appClose('applyfor',api);
				}else{
				api.alert({msg:data['msg']},function(index,err){
						appClose('applyfor',api);
					});
				}

				
			}
		});	
		
		}
		$('.tel').click(function(){
			var type = api.systemType;
			api.call({
			    type: 'tel_prompt',
			    number: tel.number
			});
		});
});

};
</script>
</body>
</html>